---

# facts

keepalived_os_family: "{{ ansible_os_family.replace(' ', '') | lower }}"

# keepalived

keepalived_scripts_user: "keepalived"
keepalived_scripts_path: "/usr/libexec/keepalived"
keepalived_scripts:
  - name: patroni-restapi-check.sh
    source: patroni-restapi-check.sh.j2

keepalived_config_source: "keepalived.conf.j2"

# Список серверов кластера. Должны быть указаны параметры host и ip всех серверов в кластере.
# Имена серверов должны соответствовать inventory_hostname
keepalived_cluster_hosts: []
# Список vip адресов.
keepalived_vip: []
#  - id: Уникальный id для vrrp_instance
#    vip: Виртуальный адрес
#    interface: Имя интерфейса
#    state: Начальное состояние адреса MASTER|BACKUP
#    priority: Приоритет сервера
#    vrrp_script: Скрипт проверки для повышения приоритета
#    check: Параметр, передаваемый в vrrp_script

# Примеры переменных для передачи в keepalived_vip, подходят для большинства случаев:
# ip адрес сервера inventory_hostname
keepalived_ip: "{{ (keepalived_cluster_hosts | items2dict(key_name='host', value_name='ip'))[inventory_hostname] }}"
# Имя группы серверов, длял выбора приоритета по умолчанию
keepalived_group_name: "{{ postgres_cluster_name }}"
# Выбор приорета по умолчанию по индексу сервера в группе
keepalived_priority: "{{ 100 - groups[keepalived_group_name].index(inventory_hostname)*10 }}"

# Пример описания для 2х vip адресов

# vip 1
#keepalived1_vip_address: "192.168.56.100/24"
#keepalived1_interface: "enp0s8"
keepalived1_id: "{{ keepalived1_vip_address.split('.')[3].split('/')[0] }}"
# vip 2
#keepalived2_vip_address: "192.168.56.110/24"
#keepalived2_interface: "enp0s8"
keepalived2_id: "{{ keepalived2_vip_address.split('.')[3].split('/')[0] }}"

# Список vip адресов
#keepalived_vip:
#  - id: "{{ keepalived1_id }}"
#    vip: "{{ keepalived1_vip_address }}"
#    interface: "{{ keepalived1_interface }}"
#    state: "MASTER"
#    priority: "{{ keepalived_priority }}"
#    vrrp_script: "patroni-restapi-check.sh"
#    check: "primary"
#  - id: "{{ keepalived2_id }}"
#    vip: "{{ keepalived2_vip_address }}"
#    interface: "{{ keepalived2_interface }}"
#    state: "MASTER"
#    priority: "{{ keepalived_priority }}"
#    vrrp_script: "patroni-restapi-check.sh"
#    check: "replica"
